package tienmanh.gs.goldminer.sprite;

import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.PathModifier;
import org.andengine.entity.modifier.SequenceEntityModifier;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierListener;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.modifier.IModifier;

import tienmanh.gs.goldminer.scene.GameScene;

public class Fish extends Object {

	@Override
	protected void onManagedUpdate(float pSecondsElapsed) {
		// TODO Auto-generated method stub
		super.onManagedUpdate(pSecondsElapsed);
		if(!GameScene.isFrzee && !isCheckMouseRun){
			if(getX() > end1 || getX() < start1){
				speed = -speed;
				isHuong = !isHuong;
				if(isHuong) animate(new long[] { 100L, 100L}, new int[]{1,0}, true);
				 else      animate(new long[] { 100L, 100L}, new int[]{3,2}, true);
			}
			setPosition(getX()+speed, getY());
		}
	}
	private  boolean isHuong;
	private  boolean isCheckMouseRun;
	private Sprite sprite;
	private VertexBufferObjectManager vbom;
	public boolean left , right;
	public float start1,start2,end1,end2,speed;
		@Override
		public void pullBackGold(float paramFloat1, float paramFloat2,
				float paramFloat3, float paramFloat4, boolean paramBoolean) {
			// TODO Auto-generated method stub
			super.pullBackGold(paramFloat1, paramFloat2, paramFloat3, paramFloat4,
					paramBoolean);
			stopAnimation();
	    	unPigRun();
	    	isCheckMouseRun = true;
		}
		private SequenceEntityModifier lemRun;
		public Fish(float pX, float pY, float pWidth, float pHeight,
				ITiledTextureRegion pTiledTextureRegion,
				VertexBufferObjectManager pVertexBufferObjectManager, int paramInt,
				float paramFloat5, String paramString) {
			super(pX, pY, pWidth, pHeight, pTiledTextureRegion, pVertexBufferObjectManager,
					paramInt, paramFloat5, paramString);
			// TODO Auto-generated constructor stub
			 isCheckMouseRun = false;
					 vbom = pVertexBufferObjectManager;
					 left = false;
					 right = false;
		}
		//huong = true phai sang trai
		public void pigRun(final float paramFloat1, final float paramFloat2, final float paramFloat3, final float paramFloat4, final float paramFloat5, final boolean huong)
		  {
			 end1 = paramFloat3;
			 end2 = paramFloat4;
			 speed = paramFloat5;
			 start1 = paramFloat1;
			 start2 = paramFloat2;
			 isHuong = huong;
			 if(huong) animate(new long[] { 100L, 100L}, new int[]{1,0}, true);
			 else      animate(new long[] { 100L, 100L}, new int[]{3,2}, true);
			 
		  }
		 public void unPigRun()
		  {
		    unregisterEntityModifier(this.lemRun);
		  }
}
